(function init() {
  console.log('插件已启动')
  $(document).keydown(function(event) {
    if (event.altKey) {
      if (event.keyCode === 87) {
        gotoItem(-1)
      } else if (event.keyCode === 83) {
        gotoItem(1)
      } else if (event.keyCode === 81) {
        window.open('https://t.bilibili.com/?tab=8') /*ctrl+q进入今日列表页面*/
      }
    }
  });
})()


let currentIndex = -1
function gotoItem(change) {
  const list = [
    '#bili_live',
    '#bili_douga',
    '#bili_anime',
    '#bili_guochuang',
    '#bili_manga',
    '#bili_music',
    '#bili_dance',
    '#bili_game',
    '#bili_technology',
    '#bili_cheese',
    '#bili_digital',
    '#bili_life',
    '#bili_food',
    '#bili_kichiku',
    '#bili_fashion',
    '#bili_information',
    '#bili_ent',
    '#bili_read',
    '#bili_movie',
    '#bili_teleplay',
    '#bili_cinephile',
    '#bili_documentary'
  ]
  currentIndex += change
  if (currentIndex < 0) {
    currentIndex = -1
    window.scrollTo({
      top: 0,
      behavior: 'smooth'
    })
    return
  } else if (currentIndex >= list.length) {
    currentIndex = list.length - 1
  }
  const dom = document.querySelector(list[currentIndex])
  if (dom) {
    const top = (dom.getBoundingClientRect()?.top || 0) + document.documentElement.scrollTop
    window.scrollTo({
      top,
      behavior: 'smooth'
    })
  }
}